package com.zzh.lib.plugin.ctx;

import android.app.Application;
import android.content.Context;

import com.zzh.lib.plugin.install.Config;

import org.xutils.http.xHttp;

/**
 * @Date: 2021/5/27 09:22
 * @Email: zzh_hz@126.com
 * @QQ: 1299234582
 * @Author: zzh
 * @Description: 宿主
 */
public final class Host extends Plugin {

    public Host(Application app, Config config) {
        super(app, config);
        HostParentClassLoader.init(this);
    }

    @Override
    public Class<?> loadClass(String name) throws ClassNotFoundException {
        Class<?> result = null;
        HostParentClassLoader hostParentClassLoader = HostParentClassLoader.getInstance();
        if (hostParentClassLoader == null) {
            result = this.getClassLoader().loadClass(name);
        } else {
            result = hostParentClassLoader.loadClass(name);
        }
        return result;
    }

    @Override
    public Context getApplicationContext() {
        return xHttp.app();
    }
}
